package com.czk.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/3/20 13:52
 */
@Configuration
public class TokenConfig {
    /**
     * 秘钥串
     */
    private String SINGING_KEY = "uaa123";

    /**
     * @return
     */
    @Bean
    public TokenStore tokenStore() {
        // 定义jwt的令牌方式
        return new JwtTokenStore(accessTokenConventer());
        // 使用内存存储令牌
      //    return new InMemoryTokenStore();
    }

    @Bean
    public JwtAccessTokenConverter accessTokenConventer() {
        JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
        // 设置秘钥
        converter.setSigningKey(SINGING_KEY);
        return converter;
    }
}
